﻿// wxWidgetsCMakeProject.cpp : Defines the entry point for the application.
//

#include "wxWidgetsCMakeProject.h"

// Start of wxWidgets "Hello World" Program
#include <wx/wx.h>
#include <wx/listctrl.h>

using namespace std;

class MyApp : public wxApp
{
public:
    bool OnInit() override;
};

wxIMPLEMENT_APP(MyApp);

class MyFrame : public wxFrame
{
public:
    MyFrame();

private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};

enum
{
    ID_Hello = 1
};

bool MyApp::OnInit()
{
    MyFrame* frame = new MyFrame();
    frame->Show(true);
    return true;
}

MyFrame::MyFrame()
    : wxFrame(nullptr, wxID_ANY, "Hello World")
{
    SetSize(wxSize(1024, 768));
    wxIcon mainicon;
    mainicon.LoadFile("icon/giftbox.ico", wxBITMAP_TYPE_ICO);
    SetIcon(mainicon);

    wxMenu* menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
        "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);

    wxMenu* menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);

    wxMenuBar* menuBar = new wxMenuBar;
    menuBar->Append(menuFile, "&File");
    menuBar->Append(menuHelp, "&Help");

    SetMenuBar(menuBar);

    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");

    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);

    wxToolBar* toolBar = CreateToolBar();
    wxImage wxImg("bmp/480-360-sample.bmp");
    toolBar->SetToolBitmapSize(wxSize(32, 32));
    toolBar->AddTool(wxID_NEW, "New", wxBitmapBundle(wxImg));
    toolBar->Realize();

    wxPanel* panel = new wxPanel(this);

    wxButton* button = new wxButton(panel, 33, "Button", wxPoint(350, 50), wxSize(100, 35));
    wxButton* button2 = new wxButton(panel, 25, "按钮", wxPoint(350, 100), wxSize(100, 35));
    // 绑定按钮点击事件
    Bind(wxEVT_BUTTON, [](wxCommandEvent& event) {
        if (event.GetId() == 25) {
            wxMessageBox(wxT("都叫你别按！"), wxT("别按"), wxOK | wxICON_INFORMATION);
        }
        else {
            wxMessageBox(wxT("你好！"), wxT("按我"), wxOK | wxICON_INFORMATION);
        }
        }, 20, 40);

    wxListView* listView = new wxListView(panel, wxID_ANY,
        wxDefaultPosition, wxSize(250, 200));
    listView->AppendColumn("Column 1");
    listView->AppendColumn("Column 2");

    // Add three items to the list
    listView->InsertItem(0, "Item 1");
    listView->InsertItem(1, "Item 2");
    listView->InsertItem(2, "Item 3");

}

void MyFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a wxWidgets Hello World example",
        "About Hello World", wxOK | wxICON_INFORMATION);
}

void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}





